﻿@model PagedList.IPagedList<FTBS.Models.Entities.Theater>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
    ViewBag.Title = "Quản lý rạp phim";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    var isSortDes = (bool)ViewBag.IsSortDes;
    var messageCanNotDelete = TempData["CanNotDelete"] ?? string.Empty;
}

<legend style="margin-top: 10px">QUẢN LÝ RẠP PHIM</legend>

<p>
    @Html.ActionLink("Thêm rạp phim", "Create")
</p>

<div>

    <div>
    @using (Html.BeginForm("Index", "Theater", FormMethod.Get))
    {
        <p>
            Tìm kiếm: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
            <input class="inverse" type="submit" value="Tìm" />
        </p>
    }
    </div>

    <div style="height: 330px; width: 100%">
        <table class="table striped bordered hovered">
            <tr>
                <th>
                    @Html.ActionLink("Tên rạp phim", "Index", new { sortOrder = ViewBag.NameSortParm, isSortDescending = isSortDes }) 
                </th>
                <th>
                    @Html.ActionLink("Địa chỉ", "Index", new { sortOrder = "address_desc", isSortDescending = isSortDes }) 
                </th>
                <th>
                    @Html.ActionLink("Số điện thoại", "Index", new { sortOrder = "phone_desc", isSortDescending = isSortDes }) 
                </th>
                <th colspan="2"></th>
            </tr>
            @foreach (var item in Model)
            {
                <tr>
                    <td style="width: 30%">
                        @Html.DisplayFor(theaterName => item.TheaterName)
                    </td>
                    <td style="width: 50%">
                        @Html.DisplayFor(address => item.Address)
                    </td>
                    <td style="width: 20%; text-align:center">
                        @Html.DisplayFor(phoneNumber => item.PhoneNumber)
                    </td>
                    <td>
                        @Html.ActionLink("Sửa", "Edit", new { id = item.TheaterId })
                    </td>
                    <td>
                        @using (Html.BeginForm("Delete", "Theater", new { id = item.TheaterId }, FormMethod.Post,
                                   new { onsubmit = "return confirm('Bạn có chắc chắn muốn xóa rạp phim này không?');" }))
                        {
                            @Html.HttpMethodOverride(HttpVerbs.Delete)
                            <button type="submit" style="background: none; border: none; display: inline; font: inherit; margin: 0; padding: 0; outline: none; outline-offset: 0; /* Additional styles to look like a link */                                                                                                                                         color: #2e92cf; cursor: pointer;">
                                Xóa</button>
                        }
                    </td>
                </tr>
            }
        </table>
    </div>
    <div style="float:right">
            <br />
        <div style="float:right">
            Trang @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) của @Model.PageCount trang
        </div>
        <div>
            @Html.PagedListPager(Model, page => Url.Action("Index",
            new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
        </div>
    </div>
</div>
<script>
    var messageCanNotDelete = '@messageCanNotDelete';
    if (messageCanNotDelete)
        alert("Rạp chiếu đang được sử dụng cho lịch chiếu. Không thể xóa!");
</script>



